import { _decorator, CircleCollider2D, Component, Node } from 'cc';
import { Monster } from './Monster';
import { Chariot } from './Chariot';
import { GameManager } from './GameManager';
import { TASKTYPE } from '../AshFramework/Datas/GameConstant';
import { GameUtil } from './GameUtil';
import { BattleManager } from './BattleManager';
const { ccclass, property } = _decorator;

enum AniState {
    Move = "Monster2_Move",
    Attack = "Monster2_Attack",
    Die = "Monster2_Die",
}


@ccclass('Monster_2')
export class Monster_2 extends Monster {

    attack() {
        this.PlayAni(AniState.Attack, () => {
            this._isPlaying = false;
            Chariot.Instance.beHit(this.Harm);
            this.PlayAni(AniState.Move)
        })
    }

    die() {
        this.scheduleOnce(() => {
            this._rigidBody.enabled = false;
            this.node.getComponents(CircleCollider2D).forEach(e => e.enabled = false);
            this.PlayAni(AniState.Die, () => {
                GameManager.Instance.userData.wipeOut[GameManager.Instance.userData.epoch][GameManager.Instance.userData.lv]++;
                if (GameManager.Instance.userData.task.type === TASKTYPE.MONSTER) {
                    GameManager.Instance.userData.task.curProgress++;
                }
                GameUtil.getAwardByMonster(this.node.getWorldPosition().clone(), BattleManager.Instance.getUIGoldWorldPos(), () => {
                    if (this.node && this.node.isValid) {
                        this.node.destroy();
                    }
                    BattleManager.Instance.addAwardGold(this.AwardGold);
                })
            })
        })
    }

}


